<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="axios,">





  <link rel="alternate" href="/blog/atom.xml" title="编程那点事" type="application/atom+xml">






<meta name="description" content="回顾下Promise Promise的基础知识不做多介绍可以参考两个文章  《ECMAScript 6 入门》：Promise 对象 ES6 Promise的resolved深入理解 这个是我看到的对于Promise状态解释比较清晰的一个文章   Promise的状态  Promise状态一旦改变就不能再变，一直保持此状态 Promise可以被其他Promise锁定—-这个很重要，跟后面的要说到的">
<meta name="keywords" content="axios">
<meta property="og:type" content="article">
<meta property="og:title" content="Axios的拦截器原理以及请求等待重发的实现">
<meta property="og:url" content="https://lhweb.gitee.io/blog/2018/09/24/Axios的拦截器原理以及请求等待重发的实现/index.html">
<meta property="og:site_name" content="编程那点事">
<meta property="og:description" content="回顾下Promise Promise的基础知识不做多介绍可以参考两个文章  《ECMAScript 6 入门》：Promise 对象 ES6 Promise的resolved深入理解 这个是我看到的对于Promise状态解释比较清晰的一个文章   Promise的状态  Promise状态一旦改变就不能再变，一直保持此状态 Promise可以被其他Promise锁定—-这个很重要，跟后面的要说到的">
<meta property="og:locale" content="default">
<meta property="og:image" content="https://lhweb.gitee.io/blog/2018/09/24/Axios的拦截器原理以及请求等待重发的实现/5637148-48325488140d9304.png">
<meta property="og:image" content="https://lhweb.gitee.io/blog/2018/09/24/Axios的拦截器原理以及请求等待重发的实现/5637148-37f4199fd75e8492.png">
<meta property="og:updated_time" content="2019-10-03T05:53:45.844Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Axios的拦截器原理以及请求等待重发的实现">
<meta name="twitter:description" content="回顾下Promise Promise的基础知识不做多介绍可以参考两个文章  《ECMAScript 6 入门》：Promise 对象 ES6 Promise的resolved深入理解 这个是我看到的对于Promise状态解释比较清晰的一个文章   Promise的状态  Promise状态一旦改变就不能再变，一直保持此状态 Promise可以被其他Promise锁定—-这个很重要，跟后面的要说到的">
<meta name="twitter:image" content="https://lhweb.gitee.io/blog/2018/09/24/Axios的拦截器原理以及请求等待重发的实现/5637148-48325488140d9304.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://lhweb.gitee.io/blog/2018/09/24/Axios的拦截器原理以及请求等待重发的实现/">





  <title>Axios的拦截器原理以及请求等待重发的实现 | 编程那点事</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="default">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">编程那点事</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://lhweb.gitee.io/blog/blog/2018/09/24/Axios的拦截器原理以及请求等待重发的实现/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="lhweb">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="编程那点事">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Axios的拦截器原理以及请求等待重发的实现</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-09-24T13:55:27+08:00">
                2018-09-24
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/javascript/" itemprop="url" rel="index">
                    <span itemprop="name">javascript</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="回顾下Promise"><a href="#回顾下Promise" class="headerlink" title="回顾下Promise"></a>回顾下Promise</h1><ol>
<li><p>Promise的基础知识不做多介绍可以参考两个文章</p>
<ol>
<li><a href="http://es6.ruanyifeng.com/#docs/promise" target="_blank" rel="noopener">《ECMAScript 6 入门》：Promise 对象</a></li>
<li><a href="https://www.cnblogs.com/JuFoFu/p/6692055.html" target="_blank" rel="noopener">ES6 Promise的resolved深入理解</a> 这个是我看到的对于Promise状态解释比较清晰的一个文章</li>
</ol>
</li>
<li><p>Promise的状态</p>
<ol>
<li>Promise状态一旦改变就不能再变，一直保持此状态</li>
<li>Promise可以被其他Promise锁定—-这个很重要，跟后面的要说到的Axios的请求3阻塞等待有关系</li>
<li>一个重要的Demo<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">Promise</span>.resolve(</span><br><span class="line">    <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve,reject</span>) =&gt;</span> &#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">'inner Promise'</span>);</span><br><span class="line">        resolve(<span class="string">'123'</span>);</span><br><span class="line">    &#125;).then(<span class="function"><span class="params">data</span>=&gt;</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="number">1</span>,<span class="keyword">typeof</span>(data), data);</span><br><span class="line">        <span class="keyword">return</span> data+<span class="string">'4'</span>;</span><br><span class="line">    &#125;)</span><br><span class="line">).then(<span class="function"><span class="params">data</span>=&gt;</span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">Promise</span>.resolve(<span class="string">'Randy'</span>+data);</span><br><span class="line">&#125;).then(<span class="function"><span class="params">data</span>=&gt;</span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="number">2</span>,<span class="keyword">typeof</span>(data), data)</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
</li>
</ol>
<ul>
<li>输出如下结果<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">inner <span class="built_in">Promise</span></span><br><span class="line"><span class="string">"string"</span> <span class="string">"123"</span></span><br><span class="line"><span class="string">"string"</span> <span class="string">"Randy1234"</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>简单解释下上面的结果</p>
<ol>
<li><code>Promise.resolve</code>创建一个<code>Promise</code>对象，依赖于inner的Promise的resolve结果</li>
<li>内部的<code>new Promise().then()</code>创建了一个Promise，<code>new Promise()resolve</code>的结果是123，then()将结果改为1234，打印”string” “123”，然后返回’1234’这个作为外层的resolve结果</li>
<li>外层中第一个then()返回了一个Promise返回”Randy1234”作为resolve结果</li>
<li>外层中第二个then()接收到前一个的返回值，然后打印”string” “Randy1234”</li>
</ol>
</li>
<li><p>人话描述下这里用到的几个知识点</p>
<ol>
<li>Promise.resolve(data)等于new Promise(resolve=&gt;{resolve(data)})</li>
<li>Promise A可以使用另一个Promise B的resolve值作为自己的resolve值进入A的调用链</li>
<li>then()可以对处理结果进行修改</li>
</ol>
</li>
</ol>
<h1 id="Axios"><a href="#Axios" class="headerlink" title="Axios"></a>Axios</h1><p>接下来开始整体，说说Axios。Axios是基于Promise机制实现的异步的链式请求框架。体积小，源码易懂。非常适合做基础的请求库。</p>
<h1 id="Axios结构"><a href="#Axios结构" class="headerlink" title="Axios结构"></a>Axios结构</h1><ol>
<li><p>代码结构</p>
<ol>
<li>axios.js：入口文件，将Axios实例的request函数绑定为入口函数，axios.create其实返回的是一个function，就是Axios实例的Axios.prototype.request</li>
<li>lib/Axios.js：真正的Axios的实例，用于拼接拦截器的调用链，关键代码如下：</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Hook up interceptors middleware</span></span><br><span class="line"><span class="keyword">var</span> chain = [dispatchRequest, <span class="literal">undefined</span>];</span><br><span class="line"><span class="keyword">var</span> promise = <span class="built_in">Promise</span>.resolve(config);</span><br><span class="line"></span><br><span class="line"><span class="keyword">this</span>.interceptors.request.forEach(<span class="function"><span class="keyword">function</span> <span class="title">unshiftRequestInterceptors</span>(<span class="params">interceptor</span>) </span>&#123;</span><br><span class="line">chain.unshift(interceptor.fulfilled, interceptor.rejected);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="keyword">this</span>.interceptors.response.forEach(<span class="function"><span class="keyword">function</span> <span class="title">pushResponseInterceptors</span>(<span class="params">interceptor</span>) </span>&#123;</span><br><span class="line">chain.push(interceptor.fulfilled, interceptor.rejected);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span> (chain.length) &#123;</span><br><span class="line">promise = promise.then(chain.shift(), chain.shift());</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">return</span> promise;</span><br></pre></td></tr></table></figure>
<ol start="3">
<li><code>lib/InterceptorManager.js</code>：拦截器管理，是一个对[]的封装</li>
<li><code>lib/dispatchRequest.js</code>：发送请求的Promise，完成发送请求的逻辑。注意看<code>Axios.js</code>中的<code>var chain = [dispatchRequest, undefined];</code></li>
<li><code>adapter/*</code>：适配器，这里的代码保证了Axios在ssr模式下和浏览器环境中区分环境实现请求返送的逻辑。里面存放了两个定义好的适配器，可以参照README.md中的描述自定义适配器</li>
</ol>
</li>
<li><p>拦截器模型</p>
</li>
</ol>
<p><img src="/blog/2018/09/24/Axios的拦截器原理以及请求等待重发的实现/5637148-48325488140d9304.png" alt="Axios拦截器示意图.png"></p>
<ul>
<li>request和response的拦截器都可以有多对，其中每一个点都会挂在一个then()的调用上，<code>promise.then(chain.shift(), chain.shift());</code></li>
</ul>
<h1 id="使用场景：应对OAuth中refresh-token换access-token时其他请求需等待的问题"><a href="#使用场景：应对OAuth中refresh-token换access-token时其他请求需等待的问题" class="headerlink" title="使用场景：应对OAuth中refresh_token换access_token时其他请求需等待的问题"></a>使用场景：应对OAuth中refresh_token换access_token时其他请求需等待的问题</h1><ul>
<li><p>根据场景来看，我们需要有一下几个能力</p>
<ol>
<li>Request拦截器中任意的请求(比如请求A)进入之后，如果主动检测到了access_token的超时，那么停止当前请求A，开启refresh_token的请求，当成功之后再执行A请求</li>
<li>当请求已发送，服务端识别到了token失效，Response拦截器中的处理跟Request拦截器要做的事一样</li>
<li>当有进行中的refresh_token请求时，此请求需要等待这个进行中的refresh_token的请求成功之后再进行发送</li>
</ol>
<ul>
<li><p>那我们一个一个来处理</p>
<ul>
<li><p>当请求进入拦截器，主动发现需要refresh_token时(比如access_token有效期临近)需要将请求放置在refresh_token成功之后</p>
</li>
<li><p>处理方式可以采用在then()调用拦截器的方法时返回一个Promise，然后在Promise中等待refresh_token的请求成功之后再进行当前进入的请求的发送</p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">   <span class="comment">// axios 的 request拦截器</span></span><br><span class="line">axios.interceptors.request.use(<span class="function"><span class="params">config</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function"><span class="params">resolve</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="comment">// 模拟等待refresh_token</span></span><br><span class="line">        setTimeout(<span class="function"><span class="keyword">function</span> (<span class="params">config_param</span>) </span>&#123;</span><br><span class="line">            resolve(config_param);</span><br><span class="line">        &#125;, <span class="number">2000</span>, config)</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<ul>
<li>上面的代码只是一个简单的示意，实际处理中要注意以下几点，<ul>
<li>刷新token之后config_param要处理新Token的拼装；</li>
<li>请求拦截器中要能识别出是否是refresh_token的请求；</li>
<li>能识别出是否正在进行refresh_token，并能正确处理其他进入的请求，这个后面会讲到</li>
</ul>
</li>
<li>处理之后调用链会变成这样</li>
</ul>
<p>   <img src="/blog/2018/09/24/Axios的拦截器原理以及请求等待重发的实现/5637148-37f4199fd75e8492.png" alt="请求拦截器中加入Promise"></p>
<ol start="2">
<li><p>当请求已发送，服务端识别到了Token失效时(这个情况比较多，服务器时间与本地有间隙；Token不支持多点登陆等等)，需要先refresh_token，然后重发请求</p>
</li>
<li><p>可以采用与Request拦截器相似的处理，在拦截器中同样开启refresh_token，成功之后重新创建已经失败的请求，执行完请求之后将重新创建的请求获取到的返回值resolve给response的返回值</p>
</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> res = response.data;</span><br><span class="line"><span class="keyword">switch</span> (res.code) &#123;</span><br><span class="line">    <span class="keyword">case</span> RespStatus.UNAUTHORIZED.code: &#123;</span><br><span class="line">        <span class="keyword">let</span> respConfig = response.config;</span><br><span class="line">        <span class="keyword">if</span> (isRefreshTokenReq(respConfig.url)) &#123;</span><br><span class="line">            <span class="comment">//刷新Token的请求如果出现401直接退出登录</span></span><br><span class="line">            showLoginOut();</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            logDebug(<span class="string">'请求的返回值出现401，由请求'</span> + config.url + <span class="string">'的返回值触发，开始进行refresh_token！'</span>);</span><br><span class="line">            <span class="keyword">let</span> auth = storage.state.user.auth;</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                res = doRefreshToken(auth.refresh_token, auth.wmq_d_current_username, respConfig)</span><br><span class="line">                    .then(<span class="function"><span class="params">config</span> =&gt;</span> &#123;</span><br><span class="line">                        <span class="keyword">return</span> wmqhttp(attachAuthInfoToConfig(storage.state.user.auth, config));</span><br><span class="line">                    &#125;).then(<span class="function"><span class="params">value</span> =&gt;</span> &#123;</span><br><span class="line">                        <span class="keyword">return</span> <span class="built_in">Promise</span>.resolve(value);</span><br><span class="line">                    &#125;);</span><br><span class="line">            &#125; <span class="keyword">catch</span> (e) &#123;</span><br><span class="line">                <span class="built_in">console</span>.log(<span class="string">'无法等待刷新Token！'</span>, e);</span><br><span class="line">                showLoginOut();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">default</span>:</span><br><span class="line">        logDebug(<span class="string">'Axios response default data：'</span>, res);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">return</span> res;</span><br></pre></td></tr></table></figure>
<p>处理之后调用链会变成这样</p>
<p>响应拦截器中加入Promise和二次请求<br>对于在refresh_token时其他请求的进入需要安排这个请求动作，让请求发生在refresh_token之后进行</p>
<ul>
<li>解决思路如下，在全局的状态中记录是否正在刷新请求，并且保存refresh_token的Promise。当遇到请求之后新创建一个Promise交给拦截器，在新创建的Promise中用then()等待refresh_token。</li>
</ul>
<pre><code>new Promise(resolve =&gt; {
    pendingPromise.then(() =&gt; {
        logDebug(&apos;刷新Token成功，开始处理之前等待的请求&apos;, config.url);
        resolve(attachAuthInfoToConfig(storage.state.user.auth, config));
    });
});
</code></pre>
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/axios/" rel="tag"># axios</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/09/24/关于-React-Router-4-的一切/" rel="next" title="关于 React Router 4 的一切">
                <i class="fa fa-chevron-left"></i> 关于 React Router 4 的一切
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/09/25/Vue-with-Typescript 系列(一) --概述/" rel="prev" title="Vue-with-Typescript 系列(一) --概述">
                Vue-with-Typescript 系列(一) --概述 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">lhweb</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">39</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">categories</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blog/tags/index.html">
                  <span class="site-state-item-count">25</span>
                  <span class="site-state-item-name">tags</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/blog/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#回顾下Promise"><span class="nav-number">1.</span> <span class="nav-text">回顾下Promise</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Axios"><span class="nav-number">2.</span> <span class="nav-text">Axios</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Axios结构"><span class="nav-number">3.</span> <span class="nav-text">Axios结构</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#使用场景：应对OAuth中refresh-token换access-token时其他请求需等待的问题"><span class="nav-number">4.</span> <span class="nav-text">使用场景：应对OAuth中refresh_token换access_token时其他请求需等待的问题</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">lhweb</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
